package CS503;

import java.util.ArrayList;

/**
 * for input n, generate all possible bits of string of length n
 * 
 * @author Xi
 * 
 */
public class StringSet {

	public static void main(String[] argv) {

		StringSet ss = new StringSet(4);
		ss.generateStringSet();
		ss.pringRes();
	}

	private ArrayList<String> stringSet;
	private int setSize = 0;

	public StringSet(int i) {
		stringSet = new ArrayList<String>();
		setSize = i;
	}

	private void generateStringSet() {

		int temp = stringSet.size();

		if (temp == 0)
			for (int i = 97; i <= 122; i++)
				stringSet.add(Character.toString((char) i));
		else
			for (int i = 0; i < temp; i++) {
				String s = stringSet.get(i);
				for (int j = 98; j <= 122; j++)
					stringSet.add(s + Character.toString((char) j));

				s = stringSet.get(i) + "a";
				stringSet.set(i, s);
			}

		if (stringSet.get(stringSet.size() - 1).length() != setSize
				|| !stringSet.get(stringSet.size() - 1).endsWith("z"))
			generateStringSet();

	}

	private void pringRes() {
		for (int i = 0; i < stringSet.size(); i++)
			System.out.println("Result " + (i + 1) + ": " + stringSet.get(i));
	}
}
